<!DOCTYPE html>
<html lang="en">

<head>
    <title></title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="./vue2.js"></script>
</head>

<body>
    <div id="app">
        <father></father>
    </div>
    <script>
        var eventBus = new Vue();
        Vue.component("father", {
            template: `
                    <div>
                        <son></son>
                        <daughter></daughter>
                    </div>
                `,
            components: {
                son: {
                    template: `
                        <p>我妹妹告诉我她叫{{mySisterName}}</p>
                        `,
                    data() {
                        return {
                            mySisterName: "???"
                        }
                    },
                    mounted() {
                        eventBus.$on("tellBroMyName", (data) => {
                            this.mySisterName = data
                        })
                    }
                },
                daughter: {
                    template: `
                        <button @click="getMyName">点我就告诉我的名字叫{{myName}}</button>`,
                    data() {
                        return {
                            myName: "兰兰"
                        }
                    },
                    methods: {
                        getMyName() {
                            eventBus.$emit("tellBroMyName", this.myName);
                        }
                    }
                }
            }
        });

        var vm = new Vue({
            el: '#app',
            data: {

            }
        })
    </script>
</body>

</html>